-
Notifications
You must be signed in to change notification settings - Fork 218
feat(chat): resolve embedded file links to full code-host URLs #756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughAdds code-host-aware URL resolution for file references in assistant answers: new buildCodeHostFileUrl helper, convertLLMOutputToPortableMarkdown now accepts optional sources to resolve revisions, and AnswerCard components propagate file sources so copied Markdown contains absolute links. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant User
participant AnswerCard
participant Utils as convertLLMOutputToPortableMarkdown
participant Builder as buildCodeHostFileUrl
participant CodeHost
User->>AnswerCard: Click "Copy answer"
AnswerCard->>Utils: convertLLMOutputToPortableMarkdown(answerText, { sources })
Utils->>Builder: resolve repo, path, revision, start/end
Builder->>CodeHost: construct provider-specific URL
CodeHost-->>Builder: URL string
Builder-->>Utils: resolved URL(s)
Utils-->>AnswerCard: portable Markdown with absolute links
AnswerCard-->>User: clipboard updated
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@packages/web/src/features/chat/utils.ts`:
- Around line 403-412: Normalize the referenced file path before matching and
URL construction: strip any leading slashes (or run a POSIX normalize) on
fileName before using it to find matchingSource in options?.sources and before
calling buildCodeHostFileUrl so revision lookup doesn’t miss entries when paths
include a leading slash; update the use of fileName in the matching logic and
the url call (references: matchingSource, options?.sources, fileName, repo,
revision, buildCodeHostFileUrl).
- Around line 260-365: The buildCodeHostFileUrl function constructs URLs by
interpolating raw filePath, revision and ownerRepo which can break for spaces or
special chars; update buildCodeHostFileUrl to percent-encode path and revision
components before interpolation (e.g., encode each segment of filePath and
ownerRepo via split('/').map(encodeURIComponent).join('/'), and encode revision
with encodeURIComponent) and ensure query parameter values used for Azure DevOps
(version, path, line, lineEnd) are encoded with encodeURIComponent; keep
line/anchor logic (startLine/endLine) intact but do not percent-encode the
leading “#L” or “:”-style anchors themselves.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@packages/web/src/features/chat/utils.ts`:
- Around line 357-362: The Gerrit URL generation currently always prefixes the
revision with "refs/heads/", which breaks when the revision is a commit SHA or a
tag; update the host.includes('gerrit') branch in the URL builder to inspect
encodedRevision and choose the correct path: if encodedRevision matches a commit
SHA (e.g. 40 hex chars) use `/+/{encodedRevision}/{encodedFilePath}`, if it
represents a tag (e.g. starts with `refs/tags/` or otherwise detected as a tag)
use `/+/refs/tags/{tag}/{encodedFilePath}`, otherwise use
`/+/refs/heads/{encodedRevision}/{encodedFilePath}`; preserve the existing
startLine fragment logic (append `#${startLine}` when startLine is present) and
update any variable names (encodedRevision, encodedFilePath, startLine)
accordingly.
- Around line 330-347: The Azure DevOps branch/file query parameters are being
built using encodePathComponent (which preserves slashes), so values like
encodedFilePath and encodedRevision produce unencoded '/' in query params;
update the code that builds url (the Azure DevOps branch in the
host.includes('dev.azure.com') || host.includes('visualstudio.com') block) to
use full URL encoding for query parameter values (e.g., use encodeURIComponent
on the file path and revision instead of encodePathComponent) so that
encodedFilePath and encodedRevision become safe for query strings (slashes
become %2F) and then rebuild the url variable accordingly, preserving the
existing org/project/repoName assembly and the startLine/endLine logic.
…d add URL builder for code hosts
19095e9 to
15fd8c3
Compare
Summary
Convert embedded LLM file citations (e.g.
@file:{github.com/owner/repo::path/to/file.ext:10-20})into portable, clickable URLs that point to a file on the originating code host.
This change ensures links emitted by the model are usable by users (not local paths).
Closes #576
What I changed
packages/web/src/features/chat/utils.tsbuildCodeHostFileUrl()to construct file URLs for GitHub, GitLab, Bitbucket, Azure DevOps, Gitea, Gerrit and generic git hosts.convertLLMOutputToPortableMarkdown()now accepts an optionalsourcesarray so it can use the indexed revision for a file when available, falling back tomain.packages/web/src/features/chat/utils.test.tscovering multiple hosts, line anchors, ranges,.md/.mdxhandling, and branch resolution fromsources.Why
LLM responses embed file references for traceability. Previously those produced local paths (e.g.,
/path/to/file), which are not portable when copying as Markdown. This change converts them into full remote URLs matching the code host's expected blob/src format and preserves line anchors.Notes on platform support
Supported hosts and behaviors:
.../blob/{branch}/{path}#L{n}(adds?plain=1for raw markdown views where appropriate).../-/blob/{branch}/{path}#L{n}.../src/{branch}/{path}#lines-{n}.../_git/{repo}?path=/{path}&version=GB{branch}&line={n}If a file
source(from the LLM retrieval metadata) is provided, the code will prefer therevisionfrom that source to construct the URL instead of defaulting tomain.Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.